package com.example.sunflowers.di

import android.content.Context
import com.example.sunflowers.App
import com.example.sunflowers.data.db.AppDatabase
import com.example.sunflowers.data.db.GardenPlantingDao
import com.example.sunflowers.data.db.PlantDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 *
 * @Author： LJH
 * @Time： 2024/1/26
 * @description：告诉hilt哪些接口的实例由它负责创建
 */
@InstallIn(SingletonComponent::class)
@Module
class DatabaseModule {

    @Singleton
    @Provides
    fun provideDatabase(@ApplicationContext context: Context):AppDatabase{
        return AppDatabase.getInstance(context)
    }

    @Provides
    fun providePlantDao(appDatabase: AppDatabase):PlantDao{
        return appDatabase.plantDao()
    }

    @Provides
    fun provideGardenPlantingDao(appDatabase: AppDatabase):GardenPlantingDao{
        return appDatabase.gardenPlantingDao()
    }

}